package frontend.parser.node.decl;

import frontend.lexer.token.Token;
import frontend.parser.node.expnode.ConstExp;
import frontend.parser.node.Node;
import frontend.parser.node.TokenNode;

public class ConstDef extends Node {
    // 常数定义    ConstDef → Ident { '[' ConstExp ']' } '=' ConstInitVal  // b k

    private Token identToken;
    private int dimension = 0;
    private ConstExp[] dimLenConstExp = new ConstExp[2];
    private ConstInitVal constInitVal;
    public void addIdentTokenNode(TokenNode identTokenNode) {
        super.add(identTokenNode);
        this.identToken = identTokenNode.getToken();
    }
    public void addDimLenConstExp(ConstExp lenConstExp) {
        super.add(lenConstExp);
        if (dimension < 2) {
            dimLenConstExp[dimension++] = lenConstExp;
        }
    }
    public void addConstInitVal(ConstInitVal constInitVal) {
        super.add(constInitVal);
        this.constInitVal = constInitVal;
    }

    public int getDimension() {
        return dimension;
    }

    public ConstExp[] getDimLenConstExp() {
        return dimLenConstExp;
    }

    public ConstInitVal getConstInitVal() {
        return constInitVal;
    }

    public String getIdentName() {
        return identToken.getTokenString();
    }

    public Token getIdentToken() {
        return identToken;
    }
    // symbol manager

//    private ConstSymbol constSymbol;
//    public ConstSymbol toConstSymbol() {
//        return (this.constSymbol =
//                new ConstSymbol(identTokenNode, dimension, dimLenConstExp, constInitVal));
//    }
//
//
//    public ConstSymbol getConstSymbol() {
//        return constSymbol;
//    }
}
